package com.blb.zycommunity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.ZyCommunityInteraction;
import com.blb.zycommunity.entity.ZyComplaintSuggest;
import com.blb.zycommunity.entity.ZyOwner;
import com.blb.zycommunity.service.IZyCommunityInteractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 社区互动表 前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@RestController
@CrossOrigin
public class ZyCommunityInteractionController {

    @Autowired
    private IZyCommunityInteractionService zyCommunityInteractionService;

    @GetMapping("/interaction-pages")
    public ResponseResult<IPage<ZyOwner>> findCommunityInteractionPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                        @RequestParam(required = false,defaultValue = "5") Long size,
                                                        @RequestParam(required = false) String ownerNickname,
                                                        @RequestParam(required = false) String ownerRealName,
                                                        @RequestParam(required = false) String ownerPhoneNumber,
                                                        @RequestParam(required = false) String communityId){
        IPage<ZyCommunityInteraction> communityInteractionPage = zyCommunityInteractionService.findCommunityInteractionPage(current, size, ownerNickname, ownerRealName, ownerPhoneNumber, communityId);
        return ResponseResult.ok(communityInteractionPage);
    }

    @GetMapping("/interactions")
    public ResponseResult<List<ZyOwner>> findCommunityInteractions(@RequestParam(required = false) String communityId){
        List<ZyCommunityInteraction> communityInteractions = zyCommunityInteractionService.findCommunityInteractions(communityId);
        return ResponseResult.ok(communityInteractions);
    }

    @PostMapping("/interaction")
    public ResponseResult deleteInteraction(@RequestParam String interactionId){
        zyCommunityInteractionService.removeInteractionById(interactionId);
        return ResponseResult.ok("ok");
    }

    @PutMapping("/interaction")
    public ResponseResult saveInteraction(@RequestBody ZyCommunityInteraction communityInteraction){
        communityInteraction.setCreateTime(LocalDateTime.now());
        zyCommunityInteractionService.save(communityInteraction);
        return ResponseResult.ok("ok");
    }

    @PostMapping("/likeNuma")
    public ResponseResult addLikeNum(@RequestParam String interactionId){
        zyCommunityInteractionService.addLikeNum(interactionId);
        return ResponseResult.ok("ok");
    }

    @PostMapping("/likeNumb")
    public ResponseResult removeLikeNum(@RequestParam String interactionId){
        zyCommunityInteractionService.removeLikeNum(interactionId);
        return ResponseResult.ok("ok");
    }


}
